#pragma once
#include "ALBaseSaliency.h"

#define MAX_IMG_DIM 300
#define TOLERANCE 0.01
#define FRAME_MAX 20
#define SOBEL_THRESH 0.4

static cv::RNG MBS_RNG;

class CALSMBP : public CALBaseSaliency
{
public:
	CALSMBP();
	//CALSMBP(const cv::Mat& src);
	CALSMBP(CALStepItem* pStepItem);
	~CALSMBP();

public:
	//https://github.com/abin24/Saliency-detection-toolbox

	virtual void test();
	virtual void convert();
	virtual void convert(const Mat &src, Mat &dst);

public:
	void calculateSaliencyMap(cv::Mat*img, cv::Mat* dst);
	cv::Mat getSaliencyMap();
	void computeSaliency(bool use_geodesic = false);
	cv::Mat getMBSMap() const { return mMBSMap; }
	void rasterScan(const cv::Mat& featMap, cv::Mat& map, cv::Mat& lb, Mat& ub);

	void invRasterScan(const Mat& featMap, Mat& map, Mat& lb, Mat& ub);
	float getThreshForGeo(const Mat& src);

	void rasterScanGeo(const Mat& featMap, Mat& map, float thresh);
	void invRasterScanGeo(const Mat& featMap, Mat& map, float thresh);

	cv::Mat computeCWS(const cv::Mat src, float reg, float marginRatio);
	cv::Mat fastMBS(const std::vector<cv::Mat> featureMaps);
	cv::Mat fastGeodesic(const std::vector<cv::Mat> featureMaps);

	int findFrameMargin(const cv::Mat& img, bool reverse);
	bool removeFrame(const cv::Mat& inImg, cv::Mat& outImg, cv::Rect &roi);
	Mat doWork(
		const Mat& src,
		bool use_lab,
		bool remove_border,
		bool use_geodesic
	);

	void Reconstruct(Mat src, Mat mask, Mat& dst);
	Mat morpySmooth(Mat I, int radius);
	Mat enhanceConstrast(Mat I, double b = 0.1);
private:
	cv::Mat mSaliencyMap;
	cv::Mat mMBSMap;
	int mAttMapCount;
	cv::Mat mBorderPriorMap;
	cv::Mat mSrc;
	std::vector<cv::Mat> mFeatureMaps;
	//void whitenFeatMap(float reg);
	//void computeBorderPriorMap(float reg, float marginRatio);
};

